package com.wujilee.mqdelaytask.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wujilee.mqdelaytask.entity.EntityDelayTask;
import com.wujilee.mqdelaytask.mapper.EntityDelayTaskGeneratedMapper;
import com.wujilee.mqdelaytask.service.DelayTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author liwuji
 * @date 2024/4/12
 * @desc
 **/
@Service
@Slf4j
public class DelayTaskServiceImpl implements DelayTaskService {
    private static final long time = 1000L * 60L * 30L;
    @Resource
    private EntityDelayTaskGeneratedMapper delayTaskGeneratedMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addDelayTask(EntityDelayTask entityDelayTask) {
        delayTaskGeneratedMapper.insert(entityDelayTask);
        return true;
    }

    @Override
    public boolean updateDelayTask(EntityDelayTask entityDelayTask) {
        delayTaskGeneratedMapper.updateById(entityDelayTask);
        return false;
    }

    @Override
    public void saveDelayTask(EntityDelayTask entityDelayTask) {
        if (null == entityDelayTask.getId()) {
            addDelayTask(entityDelayTask);
        }
    }

    @Override
    public Iterable<EntityDelayTask> getDelayTask() {
        LambdaQueryWrapper<EntityDelayTask> queryWrapper = new LambdaQueryWrapper<>();
        return delayTaskGeneratedMapper.selectList(queryWrapper);
    }
}
